package Utils;

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;

public class getResponsTest {

	private static int count = 0;
	public static void main(String[] args) {

		for(int i=1;i<401;i++){
			new Thread(new getResponsTest().new getRespons(i)).start();
		}
		try {
			Thread.sleep(5000);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		System.out.println(count+"个失败的！");
	}

	class getRespons implements Runnable {
		private int i;

		public getRespons(int i) {
			this.i = i;
		}

		public void run() {
			
			for(int x=1;x<11;x++){
			try {
				URL u = new URL("http://localhost/getChatContent?roomNum=1");
				URLConnection connection = u.openConnection();
				HttpURLConnection htCon = (HttpURLConnection) connection;
				int code = htCon.getResponseCode();
				if (code == HttpURLConnection.HTTP_OK) {
					//System.out.println("第"+i+"进程第"+x+"次find the website");
					BufferedReader in = new BufferedReader(new InputStreamReader(htCon.getInputStream()));
					String inputLine;
					while ((inputLine = in.readLine()) != null){}
						//System.out.println(inputLine);
						//System.out.println("第"+i+"进程第"+x+"次find the website");
					in.close();
				} else {
					System.out.println("Can not access the website");
				}
			} catch (Exception e) {
				count++;
				//System.out.println("第"+i+"进程第"+x+"次Can not connect,这是第"+(count)+"个失败的！");
			}
		}
		}
	}
}
